#pragma once

#include <QWidget>
#include <QPixmap>
#include "ui_CQLogin.h"
#include "CQBaseWin.hpp"

enum class LoginState
{
	Closed,
	StartLogin,
	Logining,
	LoginSuccess,
	LoginFailed
};

typedef struct
{
	QString username;
	QString pic_head;
	QString sign;
}UserInfo;


class CQLogin : public QWidget, public CQBaseWin<CQLogin>
{
	Q_OBJECT

public:
	CQLogin(QWidget* parent = Q_NULLPTR);
	~CQLogin();

	LoginState get_login_state();
	UserInfo get_user_info();
	NetClient get_socket();
	ip_port_c get_ipc();

	virtual void paintEvent(QPaintEvent* event)override;
private:
	void set_def_pic();
	bool check_user_info();
	bool connect_to_server();
	virtual void mousePressEvent(QMouseEvent*)override;
	virtual void mouseMoveEvent(QMouseEvent*)override;
	virtual void mouseReleaseEvent(QMouseEvent*)override;
private slots:
	void on_btn_login_clicked();
	void on_btn_exit_clicked();
	void on_line_user_textchanged(const QString&);

signals:
	void open_main_win();

public:
	bool is_offline_mode = false;

private:
	Ui::CQLogin ui;
	std::atomic<LoginState> login_state_ = LoginState::Closed;
	NetClient sock;
	ip_port_c ipc;
};
